
import api from '../../utils/api'
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    modeList:[
      {
        icon:'/images/my/_icon_sq.png',
        name:'我的申请',
        navurl:'/pages/my_apply/index',
      },
      {
        icon:'/images/my/_icon_pl.png',
        name:'我的评价',
        navurl:'/pages/my_comment/index',
      },
      {
        icon:'/images/my/_icon_gz.png',
        name:'我的关注',
        navurl:'/pages/my_follow/index',
      }
    ],
    menuList:[
      {
        icon:'/images/my/_icon_grziliao.png',
        iconsize:'width:48rpx;height:40rpx;',
        name:'个人资料',
        navurl:'/pages/my_info/index',
      },
      {
        icon:'/images/my/_icon_jifen.png',
        iconsize:'width:40rpx;height:40rpx;',
        name:'积分',
        navurl:'/pages/my_integral/index',
      },
      {
        icon:'/images/my/_icon_jianyi.png',
        iconsize:'width:41rpx;height:36rpx;',
        name:'建议箱',
        navurl:'/pages/my_mailbox/index',
      },
      {
        icon:'/images/my/_icon_shoucang.png',
        iconsize:'width:43rpx;height:41rpx;',
        name:'我的收藏',
        navurl:'/pages/my_collect/index',
      },
      {
        icon:'/images/my/_icon_myzuzhi.png',
        iconsize:'width:44rpx;height:44rpx;',
        name:'我成立的组织',
        navurl:'/pages/my_team/index',
      },
    ],

    imageBaseURL: app.imageBaseURL,
    imageResizeParams: app.imageResizeParams,
    avatar: '',
    username:'',
    userInfo: {},
    status:0,
    reason:'',
    stname:''
  },
  gomenuPage(e) {
    let url = e.currentTarget.dataset['navurl'];
    wx.navigateTo({
      url: url
    })
  },
  //用户信息
  async getUser () {
    let data={}
    data['flag'] = 'v2index_wd'
    const {recode, result, message} = await api.send(data)
    if(recode === 'SUCC') {
      this.setData({
        userInfo:result,
      })
    }else {
      //Toast(message)
    }
  },

   //组织状态
   async getOrgApplyStatus () {
    let data={}
    data['flag'] = 'social_organization_state'
    const {recode, result, message} = await api.send(data)
    if(recode === 'SUCC') {
       console.log(result)
       let status = result.status
       let str = ''
  
      let stname = ''
      if (status == 1) {
        stname = "已申请"
        str = '/pages/my_team_status_1/index'
      } else if (status == 2) {
        stname = "审核中"
        str = '/pages/my_team_status_2/index'
      } else if (status == 3) {
        stname = "被拒绝"
        str = '/pages/my_team_status_3/index'
      }else if(status == 0){
        stname = "暂未成立可申请"
        str = '/pages/my_team/index'
      }
       this.setData({status:result.status,reason:result.reason,['menuList[4].navurl']:str,stname})
    }else {
      //Toast(message)
    }
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let avatar = app.globalData.userInfo.avatar
    let username = app.globalData.userInfo.name
    this.setData({username, avatar} )
    //this.getUser()
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // wx.hideTabBar()
    this.getOrgApplyStatus()
    this.getUser()

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})